#include<iostream>
#include<vector>
#include<climits>
#include<queue>
using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> v(n), sum(n + 1);
	for(int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	for(int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + v[i - 1];
	}
	int max_sum = INT_MIN;
	deque<int> q;
	for(int i = 1; i <= n; i++)
	{
		while(!q.empty() && sum[q.back()] > sum[i])
		{
			q.pop_back();
		}
		if(!q.empty() && sum[i] - sum[q.front()] > max_sum) 
			max_sum = sum[i] - sum[q.front()];
		q.push_back(i);
		if(i - q.front() >= m) q.pop_front();
	}
	cout << max_sum << endl;
	return 0;
}
